package com.cykj.config;

import cn.dev33.satoken.interceptor.SaInterceptor;

import cn.dev33.satoken.stp.StpUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Program: Mooc-Admin
 * @Package: com.cykj.config
 * @Author: 张俊杰
 * @Create: 2025-07-09 00:19
 * @Description: TODO
 * @Vision: 1.0
 **/
@Configuration
public class SaTokenConfigure implements WebMvcConfigurer {

    @Value("${upload}")
    private String staticResource;

    /**
     * @Description:
     * @Param:[registry]
     * @Return:void
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 自动内部调用 checkLogin()，上下文已初始化
        registry.addInterceptor(new SaInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/system/login", "/system/getValidate", "/upload/**", "/swagger-ui.html",
                        "/swagger-ui/**",
                        "/v3/api-docs",
                        "/v3/api-docs/**",
                        "/swagger-resources/**",
                        "/webjars/**",
                        "/favicon.ico");
    }

    // 映射静态资源的存放位置
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**")
                .addResourceLocations("file:" + staticResource);
    }
}


